<?php
// No direct access to this file
defined('_JEXEC') or die;
 
// import the list field type
jimport('joomla.html.html');
jimport('joomla.form.formfield');
jimport('joomla.form.helper');
JFormHelper::loadFieldClass('list');
 
/**
 * NGMenu Form Field class for the NGMenu component
 */
class JFormFieldArrowFiles extends JFormFieldList
{
	/**
	 * The field type.
	 *
	 * @var		string
	 */
	protected $type = 'ArrowFiles';
 
//	public function getLabel() {
//	}
 
	public function getInput() {
	//build the list from all css files
		$arrow_relpath = 'modules'.DS.'mod_ngmenu'.DS.'mod_ngmenu'.DS.'images'.DS.'arrow';
		$arrow_path = JPATH_ROOT.DS.$arrow_relpath;
		$arrow_folder = @dir($arrow_path);
		$arrow_values = array();
		if ($arrow_folder) {
			while ($arrow_file = $arrow_folder->read()){
				if ($arrow_file != "." && $arrow_file != ".." && $arrow_file != "CVS" && is_file("$arrow_path/$arrow_file")){
					list($width, $height) = @getimagesize("$arrow_path/$arrow_file");
					$arrow_relpath = str_replace( '\\', '/', $arrow_relpath );
					$arrow_values[] = JHtml::_('select.option', "/$arrow_relpath/$arrow_file", $arrow_file.' (w:'.$width.'px h:'.$height.'px)');
				}
			}
			$arrow_folder->close();
		}
		sort($arrow_values);

		if ($this->name == 'jform[main_arrow_image_normal]'){
			$id = 'main-arrow_image_normal';
		}
		if ($this->name == 'jform[main_arrow_image_over]'){
			$id = 'main-arrow_image_over';
		}
		if ($this->name == 'jform[main_arrow_image_active]'){
			$id = 'main-arrow_image_active';
		}
		if ($this->name == 'jform[sub_arrow_image_normal]'){
			$id = 'sub-arrow_image_normal';
		}
		if ($this->name == 'jform[sub_arrow_image_over]'){
			$id = 'sub-arrow_image_over';
		}
		if ($this->name == 'jform[sub_arrow_image_active]'){
			$id = 'sub-arrow_image_active';
		}
		
		$prefix = JURI::root(true);
		$placeholder = JURI::root().'modules/mod_ngmenu/mod_ngmenu/images/blank20.gif';
		$options = 'onChange="preview_icon(this, \''.$id.'\', \''.$placeholder.'\', \''.$prefix.'\')"';
		
		return JHtml::_('select.genericlist', $arrow_values, $this->name, $options, 'value', 'text', $this->value);
	}
}
